package com.intellagric.service.traceability.Impl.trace_process;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.dao.traceability.ProcessQrcodeDao;
import com.intellagric.mapper.TraceProcessQrcodeMapper;
import com.intellagric.pojo.RecommendTemplate;
import com.intellagric.pojo.TraceProcessQrcode;
import com.intellagric.pojo.TraceProcessQrcodeExample;
import com.intellagric.service.traceability.trace_process.ProcessQrcodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2019/6/5
 * @DESC： 生产环节二维码管理
 */
@Service
public class ProcessQrcodeServiceImpl implements ProcessQrcodeService {

    @Autowired
    private TraceProcessQrcodeMapper processQrcodeMapper;

    @Autowired
    private ProcessQrcodeDao processQrcodeDao;

    /**
     * 添加生产环节二维码
     * @param processQrcode
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addProcessQrcode(TraceProcessQrcode processQrcode) {
        if (processQrcodeMapper.insertSelective(processQrcode) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteProcessQrcode(String id) {
        if (processQrcodeMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改生产环节二维码信息
     * @param processQrcode
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editProcessQrcode(TraceProcessQrcode processQrcode) {
        if (processQrcodeMapper.updateByPrimaryKeySelective(processQrcode) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 根据id查询二维码信息
     * @param id
     * @return TraceProcessQrcode
     */
    @Override
    public TraceProcessQrcode getProcessQrcodeById(String id) {
        return processQrcodeMapper.selectByPrimaryKey(id);
    }

    /**
     * 查所有的二维码信息
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getProcessQrcodeList() {
        TraceProcessQrcodeExample processQrcodeExample = new TraceProcessQrcodeExample();
        processQrcodeExample.createCriteria().andIdIsNotNull();
        List<TraceProcessQrcode> processQrcodeList = processQrcodeMapper.selectByExample(processQrcodeExample);
        return LayuiDataGridResult.success().add(processQrcodeList,processQrcodeList.size());
    }


    /**
     * 多条件查询二维码信息
     * @param processQrcode
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getProcessQrcodeListByVo(TraceProcessQrcode processQrcode) {
        List<TraceProcessQrcode> processQrcodeList = processQrcodeDao.selectProcessQrcodeByVo(processQrcode);
        return LayuiDataGridResult.success().add(processQrcodeList,processQrcodeList.size());
    }
}
